package com.sc.nft.entity.vo;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.NotNull;
import java.util.Date;

@Data
public class GetDetailsBasedOnTheCollectionIdVO {

    @ApiModelProperty("藏品id")
    private Long collectionId;

    @ApiModelProperty("一级标题")
    private String firstTitle;

    @ApiModelProperty("盲盒商品Id")
    private Long productBoxId;

    @ApiModelProperty("详情页图")
    private String productDetailPicture;

    @ApiModelProperty("详情页图类型 1 图片 2:动图 3:3d模型")
    private Integer productDetailPictureType;

    @ApiModelProperty("总分数")
    private Integer sumCount;

    @ApiModelProperty("产品介绍")
    private String productPresentation;

    @ApiModelProperty("作者昵称")
    private String nickName;

    @ApiModelProperty("作者头像")
    private String creatorAvatarImg;

    @ApiModelProperty("购买须知")
    private String purchaseNotes;

    @ApiModelProperty("系列名称")
    private String catenaName;

    @ApiModelProperty("权益介绍")
    private String privilegePresentation;

    @ApiModelProperty("倒计时 (毫秒值)")
    private Long countdown;

    @ApiModelProperty("3d模型id")
    private String threeModelId;

    @ApiModelProperty("缩略图")
    private String creationContent;

    @ApiModelProperty("3D模型贴图")
    private String modelImg;

    @ApiModelProperty("3D模型距离")
    private String modelDistance;

    @ApiModelProperty("剩余数量")
    private Integer residue;

    @ApiModelProperty("发行方名称")
    private String daoName;

    @ApiModelProperty("是否冷却")
    private Boolean isLockedPosition;

    @ApiModelProperty("冷却描述")
    private String lockedPositionDescribe;

    @ApiModelProperty("冷却类型 0:省缺 1:时间模式 2:日期形式 时间模式是获取藏品后延后多久,日期形式是统一锁到对应的时间")
    private Integer lockedPositionType;

    @ApiModelProperty("冷却市场小时")
    @JsonIgnore
    private Integer lockedPositionHour;

    @JsonIgnore
    @ApiModelProperty("冷却到期日期")
//    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private Date lockedPositionTime;

    @ApiModelProperty(value = "兑换上限")
    private Integer upperLimit;

    @ApiModelProperty(value = "剩余可兑换数量")
    private Integer surplusCount;

    @ApiModelProperty(value = "已兑换数量")
    private Integer redeemedQuantity;

    @ApiModelProperty(value = "当前时间是否允许兑换(0-未开始，1-可兑换，2-已结束)")
    private Integer redeem;

    /**
     * 抢购时间
     */
    private Date beginTime;
    /**
     * 结束时间
     */
    private Date endTime;

    @ApiModelProperty("是否开启注册时间限制")
    private Boolean isRegisterTime;

    @ApiModelProperty("注册开始时间")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private Date registerBeginTime;

    @ApiModelProperty("注册结束时间")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private Date registerEndTime;

    @ApiModelProperty("是否符合注册时间")
    private Boolean isConforRegisterTime=Boolean.FALSE;

    public void setSurplusCount() {
        if (null != upperLimit && null != redeemedQuantity) {
            //计算剩余可兑换数量
            this.surplusCount = Math.max(upperLimit - redeemedQuantity, 0);
            //剩余可兑换数量与总数量比较 计算结果为真实剩余可兑换数量
//            this.surplusCount = Math.min(residue, surplusCount);
        }else {
            this.surplusCount=upperLimit;
        }



    }

    public void setLockedPositionDescribe() {
        // 在是冷却的情况下,根据类型进行描述
        if (this.isLockedPosition) {
            // 时间模式
            if (this.lockedPositionType.equals(1)) {
                if (this.lockedPositionHour != null) {
                    // 当时间不为空的时候,那么要把时间/24  把他变成几天几小时
                    int day = this.lockedPositionHour / 24;
                    int hour = this.lockedPositionHour % 24;
                    if (day > 0 && hour > 0) {
                        this.lockedPositionDescribe = StrUtil.format("冷却时间: {}天{}小时", day, hour);
                    } else if (day > 0 && hour == 0) {
                        this.lockedPositionDescribe = StrUtil.format("冷却时间: {}天", day);
                    } else if (day == 0 && hour > 0) {
                        this.lockedPositionDescribe = StrUtil.format("冷却时间: {}小时", hour);
                    }
                }
            }
            if (this.lockedPositionType.equals(2)) {
                if (this.lockedPositionTime != null) {
                    // 如果当前时间大于冷却截止时间.那么就把是否冷却设置为false
                    if (this.lockedPositionTime.getTime() < System.currentTimeMillis()) {
                        this.isLockedPosition = false;
                        this.lockedPositionDescribe = "冷却已到期";
                    } else {
                        this.lockedPositionDescribe = StrUtil.format("冷却结束时间: {}", DateUtil.format(this.lockedPositionTime, "yyyy-MM-dd HH:mm:ss"));
                    }
                }
            }
        }
    }
}
